home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 4 / Info_Mac IV CD-ROM (Pacific HiTech Inc.)(August 1994).iso / Periodicals / CSMP / C.S.M.P. Digest, Issue 3.016 < prev    next >
Internet Message Format  |  1994-06-09  |  71KB

  1. From: pottier@clipper.ens.fr (Francois Pottier)
  2. Subject: csmp-digest-v3-016
  3. Date: Mon, 18 Apr 94 14:57:43 MET DST
  4.  
  5. C.S.M.P. Digest             Mon, 18 Apr 94       Volume 3 : Issue 16
  6.  
  7. Today's Topics:
  8.  
  9.         AppleTalk ON and OFF
  10.         CtoPstr in THINK C 6.0
  11.         Highlight colour?
  12.         Picture Recording
  13.         Speeding up animation; questions
  14.         Tools to improve segmentation?
  15.         copy file question, code available?
  16.         skeleton code generators?
  17.  
  18.  
  19.  
  20. The Comp.Sys.Mac.Programmer Digest is moderated by Francois Pottier
  21. (pottier@clipper.ens.fr).
  22.  
  23. The digest is a collection of article threads from the internet newsgroup
  24. comp.sys.mac.programmer.  It is designed for people who read c.s.m.p. semi-
  25. regularly and want an archive of the discussions.  If you don't know what a
  26. newsgroup is, you probably don't have access to it.  Ask your systems
  27. administrator(s) for details.  If you don't have access to news, you may
  28. still be able to post messages to the group by using a mail server like
  29. anon.penet.fi (mail help@anon.penet.fi for more information).
  30.  
  31. Each issue of the digest contains one or more sets of articles (called
  32. threads), with each set corresponding to a 'discussion' of a particular
  33. subject.  The articles are not edited; all articles included in this digest
  34. are in their original posted form (as received by our news server at
  35. nef.ens.fr).  Article threads are not added to the digest until the last
  36. article added to the thread is at least two weeks old (this is to ensure that
  37. the thread is dead before adding it to the digest).  Article threads that
  38. consist of only one message are generally not included in the digest.
  39.  
  40. The digest is officially distributed by two means, by email and ftp.
  41.  
  42. If you want to receive the digest by mail, send email to listserv@ens.fr
  43. with no subject and one of the following commands as body:
  44.     help                        Sends you a summary of commands
  45.     subscribe csmp-digest Your Name    Adds you to the mailing list
  46.     signoff csmp-digest            Removes you from the list
  47. Once you have subscribed, you will automatically receive each new
  48. issue as it is created.
  49.  
  50. The official ftp info is //ftp.dartmouth.edu/pub/csmp-digest.
  51. Questions related to the ftp site should be directed to
  52. scott.silver@dartmouth.edu. Currently no previous volumes of the CSMP
  53. digest are available there.
  54.  
  55. Also, the digests are available to WAIS users as comp.sys.mac.programmer.src.
  56.  
  57.  
  58. -------------------------------------------------------
  59.  
  60. >From makmur@aramis.rutgers.edu (Hanz Makmur)
  61. Subject: AppleTalk ON and OFF
  62. Date: 18 Mar 94 21:02:12 GMT
  63. Organization: Rutgers Univ., New Brunswick, N.J.
  64.  
  65.  
  66. Hi..
  67. I am learning how to program a Mac and trying to figure out a way to 
  68. Turn ON and Off appletalk at will from a program.
  69.  
  70. Does anyone have any idea how to do this ?  There is a program called:
  71. AppleTalkON by Jon Pugh@apple that does appletalk ON and OFF. I tried
  72. to contact Jon but it looks like he is no longer at Apple.
  73.  
  74. If any one can help, I appreciate the help. A pointer or sample source
  75. code will help.
  76.  
  77. Thank you.
  78. Hanz
  79.  
  80. If possible at all, please reply by mail to: makmur@cs.rutgers.edu
  81. -- 
  82. - ---------------------------The opinions expressed in this message are 
  83. Hanz Makmur             my own and do not necessarily reflect those of 
  84. makmur@cs.rutgers.edu         The State University of New Jersey. U.S.A
  85.  
  86. +++++++++++++++++++++++++++
  87.  
  88. >From jonpugh@netcom.com (Jon Pugh)
  89. Date: Sun, 20 Mar 1994 07:41:23 GMT
  90. Organization: NETCOM On-line Communication Services (408 241-9760 guest)
  91.  
  92. Hanz Makmur (makmur@aramis.rutgers.edu) wrote:
  93.  
  94. > Does anyone have any idea how to do this ?  There is a program called:
  95. > AppleTalkON by Jon Pugh@apple that does appletalk ON and OFF. I tried
  96. > to contact Jon but it looks like he is no longer at Apple.
  97.  
  98. That doesn't mean I'm dead.  ;)
  99.  
  100. I simply call MPPOpen and MPPClose.  If you want it to stick across reboots
  101. then you also need to twiddle the PortB global.  See IM 1-3 for the 
  102. specifics.
  103.  
  104. Jon
  105.  
  106.  
  107.  
  108. +++++++++++++++++++++++++++
  109.  
  110. >From zben@ni.umd.edu (Charles B. Cranston)
  111. Date: 20 Mar 1994 19:02:31 GMT
  112. Organization: UMCP Network Infrastructures
  113.  
  114. In article <jonpughCMyDCz.GrG@netcom.com>, jonpugh@netcom.com (Jon Pugh)
  115. wrote:
  116.  
  117. > I simply call MPPOpen and MPPClose.  If you want it to stick across reboots
  118. > then you also need to twiddle the PortB global.  See IM 1-3 for the 
  119. > specifics.
  120.  
  121. I've written an INIT to force it on and off.  It does a reboot
  122. to get the change to 'take'.  Does the code below do the
  123. appropriate kind of fiddling with the PortB global?
  124.  
  125. I just dumped PRAM and found it contained 1 in one case
  126. and 2 in the other.
  127.  
  128. In particular, IM 1-3 was written when ALAP was the only LAP for
  129. AppleTalk and the extension to a world in which the Ether/Token
  130. LAPs are also an alternative is not obvious to me...
  131.  
  132. ===============
  133.  
  134. ...
  135.     Move.L    #$00010013,D0        ; Byte 13
  136.     LEA    S.Curr(A6),A0        ; Point to stack space
  137.     _ReadXPram            ; Read current setting from parameter RAM
  138.     BNE.S    @900            ; If error then get out
  139.     Move.B    #1,D1            ; Get "ON" value
  140.     Tst.L    S.Want(A6)        ; Do we want it on?
  141.     BNE.S    @040            ; Yes, go set it ON
  142.     Move.B    #2,D1            ; Else get "OFF" value
  143. @040    ;
  144.     LEA    S.Curr(A6),A0        ; Get address of current value
  145.     Move.B    (A0),D2            ; Get current value
  146.     And.B    #$0F,D2            ; Get AppleTalk config bits
  147.     Cmp.B    D2,D1            ; Is it the desired value?
  148.     BEq.S    @050            ; Yes, go check LAP status
  149. *
  150. * Rewrite AppleTalk On/Off selection in PRAM and force reboot.
  151. *
  152.     Move.B    (A0),D2            ; Get current value
  153.     And.B    #$F0,D2            ; Keep upper 4 bits
  154.     Or.B    D1,D2            ; Use our lower bits
  155.     Move.B    D2,(A0)            ; Set current value
  156.     Move.L    #$00010013,D0        ; Bytes E0 thru E3
  157.     _WriteXPram            ; Write back to parameter RAM
  158.     Move.W    #1,S.Boot(A6)        ; Set flag to force reboot
  159. ...
  160.  
  161. ===============
  162.  
  163.     Title    'Force AppleTalk and LAP settings' ;
  164. *
  165. * Module for "Force" shell.
  166. * Ben Cranston March 1, 1994
  167. *
  168.     Print    Off            ; Here be includes
  169.     Include    'RomEqu.a'        ;
  170.     Include    'Traps.a'        ;
  171.     Print    On,NoGen        ; Here be includes
  172.     Main                ; Begin module
  173. *
  174. S    Record    {A6Link},Decr        ; Stack frame
  175. A6Link    DS.L    1            ; Caller's A6
  176. SPB    DS    SpBlock            ; Slot Parameter Block
  177. Curr    DS.L    1            ; Current PRAM value
  178. Want    DS.L    1            ; Desired PRAM value
  179. Flag    DS.W    1            ; Desired PRAM setup flags
  180. Boot    DS.W    1            ; Set if reboot required
  181. SS    Equ    *            ; Stack size
  182.     EndR                ; Stack frame
  183. *
  184. * Get resource containing the desired PRAM contents.
  185. *
  186.     Link    A6,#S.SS        ; Make local frame
  187.     Clr.W    S.Boot(A6)        ; Initially set no reboot
  188.     Tst.L    D1            ; Was our data resource present?
  189.     BEq.W    @999            ; If not then just return
  190.     Move.L    D1,A0            ; Get resource handle
  191.     Move.L    (A0),A0            ; Get pointer
  192.     Move.W    (A0),S.Flag(A6)        ; Get desired value
  193. *
  194.     Eject                ;
  195. *
  196. * Test if AppleTalk is to be turned off entirely.
  197. *
  198.     Clr.L    S.Want(A6)        ; Initially set AppleTalk OFF
  199.     Move.B    S.Flag+0(A6),D1        ; Get master flag
  200.     BEq.S    @030            ; Is AppleTalk to be turned off entirely?
  201. *
  202. * Test if LocalTalk is wanted.
  203. *
  204.     Move.B    #1,S.Want+3(A6)        ; Set AppleTalk on LocalTalk
  205.     Cmp.B    #1,D1            ; Want LocalTalk or EtherTalk?
  206.     BEq.S    @030            ; Want EtherTalk, skip
  207. *
  208. * Find Ethernet card address to complete the desired PRAM value.
  209. *
  210.     LEA    S.SPB(A6),A0        ; Get spBlock address
  211.     Move.B    S.Flag+1(A6),spBlock.spSlot(A0) ; Set slot to start searching at
  212.     Clr.B    spBlock.spId(A0)    ; Find any resource number
  213.     Clr.B    spBlock.spExtDev(A0)    ; External device zero?
  214.     Clr.B    spBlock.spHwDev(A0)    ; Ignore external hardware
  215.     Move.B    #3,spBlock.spTBMask(A0)    ; Look at Category and CType
  216.     Move.W    #catNetwork,spBlock.spCategory(A0) ; Network category
  217.     Move.W    #typEtherNet,spBlock.spCType(A0) ; EtherNet type
  218.     _sNextTypesRsrc            ; Get next sResource info
  219.     BNE.W    @900            ; If nofind then get out
  220.     Move.B    spBlock.spSlot(A0),S.Want+0(A6) ; Get network card slot number
  221.     Move.B    spBlock.spId(A0),S.Want+1(A6) ; Get slot resource ID number
  222.     Clr.B    S.Want+2(A6)        ; Clear unused field
  223.     Move.B    #$A,D1            ; Get EtherTalk Phase 2 code
  224.     Cmp.B    #2,S.Flag+0(A6)        ; Did he want Phase 1?
  225.     BNE.S    @020            ; If not then assume Phase 2
  226.     Move.B    #$2,D1            ; Get EtherTalk Phase 1 code
  227. @020    ;
  228.     Move.B    D1,S.Want+3(A6)        ; Set Phase 1 / Phase 2 code
  229. *
  230.     Eject                ;
  231. *
  232. * Read PRAM for AppleTalk On/Off selection, decide if we must change it.
  233. *
  234. @030    ;
  235.     Move.L    #$00010013,D0        ; Byte 13
  236.     LEA    S.Curr(A6),A0        ; Point to stack space
  237.     _ReadXPram            ; Read current setting from parameter RAM
  238.     BNE.S    @900            ; If error then get out
  239.     Move.B    #1,D1            ; Get "ON" value
  240.     Tst.L    S.Want(A6)        ; Do we want it on?
  241.     BNE.S    @040            ; Yes, go set it ON
  242.     Move.B    #2,D1            ; Else get "OFF" value
  243. @040    ;
  244.     LEA    S.Curr(A6),A0        ; Get address of current value
  245.     Move.B    (A0),D2            ; Get current value
  246.     And.B    #$0F,D2            ; Get AppleTalk config bits
  247.     Cmp.B    D2,D1            ; Is it the desired value?
  248.     BEq.S    @050            ; Yes, go check LAP status
  249. *
  250. * Rewrite AppleTalk On/Off selection in PRAM and force reboot.
  251. *
  252.     Move.B    (A0),D2            ; Get current value
  253.     And.B    #$F0,D2            ; Keep upper 4 bits
  254.     Or.B    D1,D2            ; Use our lower bits
  255.     Move.B    D2,(A0)            ; Set current value
  256.     Move.L    #$00010013,D0        ; Bytes E0 thru E3
  257.     _WriteXPram            ; Write back to parameter RAM
  258.     Move.W    #1,S.Boot(A6)        ; Set flag to force reboot
  259.     Tst.L    S.Want(A6)        ; Did we want it off?
  260.     BEq.S    @999            ; Yes, we are done
  261. *
  262.     Eject                ;
  263. *
  264. * Read PRAM for AppleTalk LAP selection, decide if we must change it.
  265. *
  266. @050    ;
  267.     Move.L    #$000400E0,D0        ; Bytes E0 thru E3
  268.     LEA    S.Curr(A6),A0        ; Point to stack space
  269.     _ReadXPram            ; Read current from parameter RAM
  270.     BNE.S    @900            ; If error then get out
  271.     Move.B    S.Curr+1(A6),D1        ; Get current alt atalk type
  272.     Cmp.B    S.Want+1(A6),D1        ; Same as desired?
  273.     BNE.S    @060            ; No, must reset and reboot
  274.     Move.B    S.Curr+3(A6),D1        ; Get current alt level
  275.     Cmp.B    S.Want+3(A6),D1        ; Same as desired?
  276.     BEq.S    @999            ; If so then skip
  277. *
  278. * Rewrite AppleTalk LAP selection in PRAM and force reboot.
  279. *
  280. @060    ;
  281.     LEA    S.Want(A6),A0        ; Get address of desired
  282.     Move.L    #$000400E0,D0        ; Bytes E0 thru E3
  283.     _WriteXPram            ; Write back to parameter RAM
  284.     Move.W    #1,S.Boot(A6)        ; Set flag to force reboot
  285.     Bra.S    @999            ; Return to driver
  286. *
  287. * Some kind of error, just return OK status.
  288. *
  289. @900    ;
  290.     Clr.W    S.Boot(A6)        ; Set no reboot
  291. *
  292. @999    ;
  293.     Move.W    S.Boot(A6),D0        ; Set return value
  294.     UnLk    A6            ; Drop local frame
  295.     RTS                ; Return to INIT31
  296. *
  297.     EndMain                ; Keep MPW happy
  298.     End                ; ForceAppleTalk.a
  299.  
  300. +++++++++++++++++++++++++++
  301.  
  302. >From walkerj@math.scarolina.edu (Jim Walker)
  303. Date: 21 Mar 1994 02:42:16 GMT
  304. Organization: University of South Carolina - Columbia - Computer Science
  305.  
  306. jonpugh@netcom.com (Jon Pugh) writes:
  307.  
  308. >I simply call MPPOpen and MPPClose.  If you want it to stick across reboots
  309. >then you also need to twiddle the PortB global.  See IM 1-3 for the 
  310. >specifics.
  311.  
  312. When I tried MPPOpen, I got a -98 error unless I cleared the low nybble of  
  313. SPConfig first.
  314.  
  315. The current AppleTalk.h says that MPPClose is obsolete, but so far as I know 
  316. Apple has not released a new Inside Mac volume discussing AppleTalk. Anyone
  317. know what should be used instead of MPPClose?
  318.  
  319.  
  320. --
  321.  
  322.  -- Jim Walker  USC Dept. of Math.  walkerj@math.scarolina.edu
  323.  
  324. +++++++++++++++++++++++++++
  325.  
  326. >From mahboud@aggroup.com (Mahboud Zabetian)
  327. Date: Mon, 21 Mar 1994 12:43:21 -0800
  328. Organization: AG Group, Inc.
  329.  
  330. In article <2mj1i8$jki@redwood.cs.scarolina.edu>,
  331. walkerj@math.scarolina.edu (Jim Walker) wrote:
  332.  
  333. > jonpugh@netcom.com (Jon Pugh) writes:
  334. > >I simply call MPPOpen and MPPClose.  If you want it to stick across reboots
  335. > >then you also need to twiddle the PortB global.  See IM 1-3 for the 
  336. > >specifics.
  337. > When I tried MPPOpen, I got a -98 error unless I cleared the low nybble of  
  338. > SPConfig first.
  339. > The current AppleTalk.h says that MPPClose is obsolete, but so far as I know 
  340. > Apple has not released a new Inside Mac volume discussing AppleTalk. Anyone
  341. > know what should be used instead of MPPClose?
  342.  
  343. I remember seeing a TechNote that said use PBOpen (OpenDriver) and PBClose
  344. instead.  Check the Networking TechNotes.  I believe that MPPClose is one
  345. of the calls that will not be ported to the PowerPC.  I think that it will
  346. still be available emulated, but if your native app want to get to it,
  347. it'll have to go through some hoops.
  348.  
  349. -mahboud
  350.  
  351. - -------------------------------------------------------------
  352. Mahboud Zabetian
  353. mahboud@aggroup.com
  354. ag group, inc.
  355. 2540 camino diablo, suite 200
  356. walnut creek, ca 94596
  357. 510-937-7900 voice
  358. 510-937-2479 fax
  359. 510-937-6704 ara
  360. ftp.aggroup.com anonymous ftp
  361.  
  362. +++++++++++++++++++++++++++
  363.  
  364. >From Mark_Day@powertalk.apple.com (Mark Day)
  365. Date: Fri, 1 Apr 1994 18:10:08 GMT
  366. Organization: Apple Computer, Inc.
  367.  
  368. In article <2mj1i8$jki@redwood.cs.scarolina.edu>,
  369. walkerj@math.scarolina.edu (Jim Walker) wrote:
  370.  
  371. > When I tried MPPOpen, I got a -98 error unless I cleared the low nybble of  
  372. > SPConfig first.
  373.  
  374. Fiddling with SPConfig sounds kind of dangerous.  If .MPP won't open the
  375. printer port for LocalTalk, it's probably because some other piece of
  376. software says it is still using the port.  I'd suggest tracking down
  377. what other code thinks it's using the printer port, first (and make sure
  378. it clears the in use bit when it really is done with the port).
  379.  
  380. > The current AppleTalk.h says that MPPClose is obsolete, but so far as I know 
  381. > Apple has not released a new Inside Mac volume discussing AppleTalk. Anyone
  382. > know what should be used instead of MPPClose?
  383.  
  384. MPPOpen is the equivalent of OpenDriver(".MPP"), and MPPClose is equivalent
  385. to closing the .MPP driver.  Theoretically, you shouldn't close the network
  386. drivers from your application because some other application may be using
  387. them.  Ask yourself if you REALLY need to close .MPP.
  388.  
  389. If you do have a valid reason to close the driver (for example, you're
  390. providing a user with the ability to turn AppleTalk on or off, like the
  391. Chooser does), I'd suggest using OpenDriver and CloseDriver on the .MPP
  392. driver.
  393.  
  394. The other thing you should look at is the AppleTalk Transition Queue,
  395. which is used to notify clients of changes to AppleTalk's state.  I don't
  396. know enough of the details to tell you what the right thing to do is,
  397. there.
  398. It's documented, but offhand, I don't know where.
  399. -- 
  400. Mark Day, Apple Computer, Inc.
  401. mday@apple.com
  402.  
  403. +++++++++++++++++++++++++++
  404.  
  405. >From walkerj@math.scarolina.edu (Jim Walker)
  406. Date: 2 Apr 1994 04:28:54 GMT
  407. Organization: University of South Carolina - Columbia - Computer Science
  408.  
  409. Mark_Day@powertalk.apple.com (Mark Day) writes:
  410.  
  411. >If you do have a valid reason to close the driver (for example, you're
  412. >providing a user with the ability to turn AppleTalk on or off, like the
  413. >Chooser does), I'd suggest using OpenDriver and CloseDriver on the .MPP
  414. >driver.
  415.  
  416. Yes, that's the idea, I want to make a utility that turns AppleTalk on and
  417. off.  I would not do that without the user's consent.  But unlike the
  418. Chooser, I would like to be able to turn AppleTalk on without restarting the
  419. Mac.  Calling OpenDriver on .MPP just gives a -23 error in that case. 
  420. Anyone know the trick?
  421. --
  422.  
  423.  -- Jim Walker  USC Dept. of Math.  walkerj@math.scarolina.edu
  424.  
  425. +++++++++++++++++++++++++++
  426.  
  427. >From ugtalbot@mcs.drexel.edu (George T. "14K F/D" Talbot)
  428. Date: Sat, 2 Apr 94 20:54:00 GMT
  429. Organization: Drexel University
  430.  
  431. In article <2nisa6$i6u@redwood.cs.scarolina.edu> walkerj@math.scarolina.edu (Jim Walker) writes:
  432. >Mark_Day@powertalk.apple.com (Mark Day) writes:
  433. >
  434. >>If you do have a valid reason to close the driver (for example, you're
  435. >>providing a user with the ability to turn AppleTalk on or off, like the
  436. >>Chooser does), I'd suggest using OpenDriver and CloseDriver on the .MPP
  437. >>driver.
  438. >
  439. >Yes, that's the idea, I want to make a utility that turns AppleTalk on and
  440. >off.  I would not do that without the user's consent.  But unlike the
  441. >Chooser, I would like to be able to turn AppleTalk on without restarting the
  442. >Mac.  Calling OpenDriver on .MPP just gives a -23 error in that case. 
  443. >Anyone know the trick?
  444. >--
  445. >
  446. > -- Jim Walker  USC Dept. of Math.  walkerj@math.scarolina.edu
  447.  
  448. I've run into this using the .ENET driver.  You have to set the read/write
  449. permissions in the Open parameter block to fsSharedRdWrPerm (or something like
  450. that) to open the driver.  This means you'll have to use the PBOpen call,
  451. rather than OpenDriver.
  452.  
  453. Hope this helps.
  454.  
  455. -- 
  456. George T. Talbot
  457. <ugtalbot@mcs.drexel.edu>
  458. - -------------------------------------------------------------------------
  459. Finger my account for PGP public key.  |  This is very political software.
  460.  
  461. +++++++++++++++++++++++++++
  462.  
  463. >From mahboud@aggroup.com (mahboud)
  464. Date: Mon, 04 Apr 1994 15:53:33 -0800
  465. Organization: AG Group, Inc.
  466.  
  467. In article <2nisa6$i6u@redwood.cs.scarolina.edu>,
  468. walkerj@math.scarolina.edu (Jim Walker) wrote:
  469.  
  470. > Mark_Day@powertalk.apple.com (Mark Day) writes:
  471. > >If you do have a valid reason to close the driver (for example, you're
  472. > >providing a user with the ability to turn AppleTalk on or off, like the
  473. > >Chooser does), I'd suggest using OpenDriver and CloseDriver on the .MPP
  474. > >driver.
  475. > Yes, that's the idea, I want to make a utility that turns AppleTalk on and
  476. > off.  I would not do that without the user's consent.  But unlike the
  477. > Chooser, I would like to be able to turn AppleTalk on without restarting the
  478. > Mac.  Calling OpenDriver on .MPP just gives a -23 error in that case. 
  479. > Anyone know the trick?
  480. > --
  481. >  -- Jim Walker  USC Dept. of Math.  walkerj@math.scarolina.edu
  482.  
  483. If AppleTalk was off when you restarted, a major portion of its code will
  484. not be in memory and will not be loaded up with an MPPOpen (or PBOpen)
  485. call.  This cahnge was put in after the original System 7 Tuner in order to
  486. save about 100K of memory for people who are not using their macs on
  487. networks.
  488.  
  489. I think that you will have to restart if you did not have AppleTalk active,
  490. the last time you restarted.
  491.  
  492. On the other hand, I have had no trouble turning AppleTalk off and on, if
  493. it was already active.  I use MPPOpen and MPPClose.
  494.  
  495. -mahboud
  496. - -------------------------------------------------------------
  497. Mahboud Zabetian
  498. mahboud@aggroup.com
  499. ag group, inc.
  500. 2540 camino diablo, suite 200
  501. walnut creek, ca 94596
  502. 510-937-7900 voice
  503. 510-937-2479 fax
  504. 510-937-6704 ara
  505. ftp.aggroup.com anonymous ftp
  506.  
  507. ---------------------------
  508.  
  509. >From wang_dj@dev.gdb.org (David J. Wang)
  510. Subject: CtoPstr in THINK C 6.0
  511. Date: Sat, 2 Apr 1994 01:40:17 GMT
  512. Organization: Genome Database
  513.  
  514. I have a newbie programmer question.  Can anyone instruct me as to the
  515. correct way to use CtoPstr and PtoCstr.  I suppose the problem isn't
  516. so much in using those functions, but rather trying to pass the result
  517. to a function that requires a Str255 (for example DrawString() ).
  518. For example:
  519.     char *foo;
  520.     CtoPstr(foo);
  521.     DrawString(WHAT GOES IN HERE?);
  522.  
  523.     or am I totally off base.  On a related note, why does CtoPstr
  524. take a pointer to a char for an argument while PtoCstr take a pointer
  525. to an unsigned char.  This being the case, does that mean that I have
  526. to always cast one or the other?
  527.  
  528. Finally, I would appreciate any hints in getting started in Mac
  529. programming, or where I could turn (good books, etc).
  530.  
  531. Thanks,
  532.  
  533. David
  534.  
  535.  
  536. --
  537. *************************************************************************
  538. David J. Wang                 #include <std_disclaimer>
  539. wang_dj@gdb.org                 (410)614-0393
  540. wang_dj@server.cs.jhu.edu         Biology@The Johns Hopkins University
  541.                      Baltimore, Maryland 21210
  542. ************************************************************************/
  543.  
  544. +++++++++++++++++++++++++++
  545.  
  546. >From omh@cs.brown.edu (Owen M. Hartnett)
  547. Date: Sat, 2 Apr 1994 05:10:17 GMT
  548. Organization: Brown University Department of Computer Science
  549.  
  550. In article <1994Apr2.014017.6498@news.gdb.org> wang_dj@dev.gdb.org (David J. Wang) writes:
  551. >I have a newbie programmer question.  Can anyone instruct me as to the
  552. >correct way to use CtoPstr and PtoCstr.  I suppose the problem isn't
  553. >so much in using those functions, but rather trying to pass the result
  554. >to a function that requires a Str255 (for example DrawString() ).
  555. >For example:
  556. >    char *foo;
  557. >    CtoPstr(foo);
  558. >    DrawString(WHAT GOES IN HERE?);
  559. >
  560. >    or am I totally off base.  On a related note, why does CtoPstr
  561. >take a pointer to a char for an argument while PtoCstr take a pointer
  562. >to an unsigned char.  This being the case, does that mean that I have
  563. >to always cast one or the other?
  564. >
  565. >Finally, I would appreciate any hints in getting started in Mac
  566. >programming, or where I could turn (good books, etc).
  567. >
  568.  
  569. Hi David!
  570.  
  571. This is an excellent newbie question. Thanks for posing it.
  572.  
  573. Your question actually has many facets, so I will attempt to answer the
  574. whole scope here.
  575.  
  576. 1) First of all, in your code above, strictly speaking, will cause the
  577. computer to crash. The definition:
  578.     char *foo;
  579. only defines enough space for a pointer to a string of characters, not
  580. the string itself. You have to define the space yourself, as in:
  581.     char foo[255];
  582. This allocates an array of 255 characters and makes space for the
  583. characters themselves. Once you do this you can than use the name of
  584. the array, foo, as a pointer to the first character, foo[0]. Thus, you
  585. could assign it to another char pointer, as so:
  586.  
  587.     char *foo
  588.     char bar[255];
  589.  
  590.     foo = bar;
  591.  
  592. This will make the pointer foo act the same as the pointer bar.
  593.  
  594. 2) I went through the above explanation even though I thought you
  595. might already know it because of the way you used your code example.
  596. Also, I wanted to point out the fact that CtoPstr and PtoCstr change
  597. the strings *in place*. They expect that you are passing to them a
  598. pointer to a string of characters which already exist in memory, and
  599. they move the test over a byte one way or the other and write in
  600. either a trailing zero or a beginning length byte.
  601.  
  602. 3) Because of the nature of these bad boys, and that the string you want
  603. to C may be declared as C or P or vice versa, you end up casting a lot.
  604. A useful type for casting is StringPtr. This can be used to cast a
  605. char * into a Str255 * (which you can't do directly, hence your above
  606. problem.)
  607.  
  608. Thus, here is the compleat guide for string casting, along with sundry
  609. baits and lures:
  610.  
  611.     char    foo[255];
  612.     Str255    bar;
  613.  
  614.     char    mac[255];
  615.     Str255    ibm;
  616.  
  617.     /* Assume appropriate data has been moved into strings    */
  618.  
  619.     /* straight, no casting required    */
  620.  
  621.     CtoPstr(foo);
  622.     PtoCstr(bar);
  623.  
  624.     /* cast your pointers to the winds!    */
  625.  
  626.     CtoPstr((char *) ibm);
  627.     PtoCstr((StringPtr) mac);
  628.  
  629. Remember, let he whose programs are without bugs cast the first pointers.
  630.  
  631. -Owen
  632.  
  633. -Owen
  634.  
  635.  
  636. -- 
  637. Owen Hartnett                omh@cs.brown.edu
  638. "FAITH, n. Belief without evidence in what is told by one who speaks
  639.         without knowledge, of things without parallel."
  640.             -Ambrose Bierce - The Devil's Dictionary
  641.  
  642. +++++++++++++++++++++++++++
  643.  
  644. >From benh@fdn.org (Benjamin Herrenschmidt)
  645. Date: Sun, 3 Apr 94 12:36:41 +0100
  646. Organization: (none)
  647.  
  648.  
  649. Be careful to allocate your Pascal string as an array of 256 chars,
  650. not 255 ! There is the length byte !
  651.  
  652. char foo[256];    // is ok.
  653.  
  654. Str255 foo;        // is ok too
  655.  
  656. BenH.
  657.  
  658. ---------------------------
  659.  
  660. >From ikb_macd@ECE.Concordia.CA (Ian Keith Baker Mac Donald)
  661. Subject: Highlight colour?
  662. Date: Mon, 4 Apr 1994 03:59:56 GMT
  663. Organization: ECE - Concordia University
  664.  
  665. I'd like to use the highlight colour as specified by the user in the Colors
  666. control panel, can anyone tell me how to get the color information?  IM
  667. says that there's a global called HiliteRGB, but ThinkP doesn't recognize
  668. it.
  669.  
  670. Thanks,
  671. Keith
  672.  
  673.  
  674.  
  675. +++++++++++++++++++++++++++
  676.  
  677. >From rlvd_cif@uhura.cc.rochester.edu (Rob Levandowski)
  678. Date: Mon, 4 Apr 94 05:27:18 GMT
  679. Organization: University of Rochester - Rochester, New York
  680.  
  681. In <Cnpv3w.2pJ@newsflash.concordia.ca> ikb_macd@ECE.Concordia.CA (Ian Keith Baker Mac Donald) writes:
  682.  
  683. >I'd like to use the highlight colour as specified by the user in the Colors
  684. >control panel, can anyone tell me how to get the color information?  IM
  685. >says that there's a global called HiliteRGB, but ThinkP doesn't recognize
  686. >it.
  687.  
  688. >Thanks,
  689. >Keith
  690.  
  691.  
  692. Try adding "SysEqu.p" to your project.
  693.  
  694. The recommended way to use the hilight colour is detailed in Inside Mac
  695. vol. V, p. V-61. (I don't have the new IM.) Issue the command
  696.  
  697.     BitClr(Ptr(Hilite,pHiliteBit));
  698.  
  699. immediately before InvertRect,InvertRgn,InvertArc,InvertRoundRct, or
  700. InvertPoly, or any other drawing done in srcXor mode. The inversion will
  701. be done using the user-selected hilite color on a color-capable Mac;
  702. otherwise B&W is used. This is safe to call on all Macs. You must make
  703. the call immediately before each call that you want to use hilite color
  704. with; it is reset each time a drawing call is made.
  705. -- 
  706. --Rob Levandowski
  707.   Computer Interest Floor associate / University of Rochester
  708.   macwhiz@cif.rochester.edu     [Opinions expressed are mine, not UR's.]
  709.  
  710. +++++++++++++++++++++++++++
  711.  
  712. >From platypus@cirrus.som.cwru.edu (Gary Kacmarcik)
  713. Date: 04 Apr 1994 13:26:38 GMT
  714. Organization: Case Western Reserve University, Cleveland, Ohio (USA)
  715.  
  716. In article <1994Apr4.052718.8957@galileo.cc.rochester.edu> rlvd_cif@uhura.cc.rochester.edu (Rob Levandowski) writes:
  717. >
  718. > In <Cnpv3w.2pJ@newsflash.concordia.ca> ikb_macd@ECE.Concordia.CA (Ian Keith Baker Mac Donald) writes:
  719. >
  720. > >I'd like to use the highlight colour as specified by the user in the Colors
  721. > >control panel, can anyone tell me how to get the color information?  IM
  722. > >says that there's a global called HiliteRGB, but ThinkP doesn't recognize
  723. > >it.
  724. >
  725. > The recommended way to use the hilight colour is detailed in Inside Mac
  726. > vol. V, p. V-61. (I don't have the new IM.) Issue the command
  727. >
  728. >    BitClr(Ptr(Hilite,pHiliteBit));
  729. >
  730. > immediately before InvertRect,InvertRgn,InvertArc,InvertRoundRct, or
  731.  
  732. this is no longer the recommended way to do this.  in fact, accessing
  733. any Low Memory global _directly_ is frowned upon.
  734.  
  735. the proper way is to use the accessor functions:
  736.  
  737.   extern unsigned char LMGetHiliteMode(void);
  738.   extern void LMSetHiliteMode(unsigned char HiliteModeValue);
  739.  
  740. these are defined as part of the new Universal Headers (in LowMem.h)
  741.  
  742. if you compile a native version of your code using the "set the Low Mem
  743. global directly" method, you are likely to run into problems.
  744.  
  745. > This is safe to call on all Macs.
  746.  
  747. the direct method is "safe" to call on all 68k macs and PowerMacs running
  748. in 68k emulation, but not on PowerMacs in native mode.
  749.  
  750. the accessor functions will compile to the right thing on 68k and PowerPC
  751. based Macs.
  752.  
  753.  
  754. -gary j kacmarcik
  755. platypus@curie.ces.cwru.edu
  756.  
  757. +++++++++++++++++++++++++++
  758.  
  759. >From d88-jwa@mumrik.nada.kth.se (Jon W‰tte)
  760. Date: 4 Apr 1994 14:19:07 GMT
  761. Organization: The Royal Institute of Technology
  762.  
  763. In <PLATYPUS.94Apr4092638@cirrus.som.cwru.edu> platypus@cirrus.som.cwru.edu (Gary Kacmarcik) writes:
  764.  
  765. >this is no longer the recommended way to do this.  in fact, accessing
  766. >any Low Memory global _directly_ is frowned upon.
  767.  
  768. That's because the new Macintosh OS will supposedly do away with
  769. the globals, but retain accessors for the equivalent functionality.
  770.  
  771. >  extern unsigned char LMGetHiliteMode(void);
  772. >  extern void LMSetHiliteMode(unsigned char HiliteModeValue);
  773. >these are defined as part of the new Universal Headers (in LowMem.h)
  774.  
  775. Yes, but using the lo-mem global at all is only marginally
  776. better than addressing it directly. Instead, use PenMode(hilite)
  777. like so:
  778.  
  779.     PenMode ( hilite ) ;
  780.     InvertRgn ( selectionRgn ) ;
  781.  
  782. >if you compile a native version of your code using the "set the Low Mem
  783. >global directly" method, you are likely to run into problems.
  784.  
  785. No problem. ALL lo-mem globals are still there on the PowerPC.
  786. I spoke to an engineer who translated part of ROM (things like
  787. Button :-) and he said they pretty much kept ALL quirks of the
  788. ROM, for compatibility (like journalling, which is why Button
  789. may move memory)
  790.  
  791. -- 
  792.  -- Jon W{tte, h+@nada.kth.se, Mac Hacker Deluxe --
  793.     Not speaking for the Liberian Government.
  794.  
  795. ---------------------------
  796.  
  797. >From weip@engin.umich.edu (Patrick Wei)
  798. Subject: Picture Recording
  799. Date: 4 Apr 1994 17:22:32 GMT
  800. Organization: University of Michigan Engineering, Ann Arbor
  801.  
  802.  
  803. I can't seem to get drawing information recorded into a picture that is loaded from
  804. a resource file. Should I call OpenPicture in addition to DrawPicture?
  805.  
  806. The code is the following:
  807.  
  808. - --------------------------------
  809.     resFileNum = OpenResFile( (ConstStr255Param) pictInfo[j].name);
  810.     if((thePicture = GetPicture( (short) pictInfo[j].id)) == 0)
  811.     {
  812.         printf("can't get picture\n");
  813.         goto end_of_loop;
  814.     }
  815.  
  816.     r = (*thePicture)->picFrame;
  817.     width = r.right - r.left;
  818.     height = r.bottom - r.top;
  819.         
  820.     SetRect(&r, 0, 0, width, height);
  821.     OffsetRect(&r, 50, 50);
  822.     
  823.     DrawPicture(thePicture, &r);
  824.  
  825.     followed by a bunch of Line and LineTo operations. 
  826.  
  827.     //save resource    
  828.     {
  829.     Handle pictHandle;
  830.     PtrToHand(*thePicture, &pictHandle, (*thePicture)->picSize);
  831.     AddResource(pictHandle, 'PICT', 401, "\p");     
  832.     CloseResFile(resFileNum);
  833.     }
  834. - --------------------------------------
  835.  
  836. When I tried the save thePicture, the original picture is saved to disk, not the altered
  837. version that I want. The drawing information is never recorded into the picture
  838.  
  839. +++++++++++++++++++++++++++
  840.  
  841. >From Carl R. Osterwald <carl_osterwald@nrel.gov>
  842. Date: Mon, 4 Apr 94 21:43:51 GMT
  843. Organization: National Renewable Energy Laboratory
  844.  
  845. In article <2npicoINNq72@srvr1.engin.umich.edu> Patrick Wei,
  846. weip@engin.umich.edu writes:
  847. >I can't seem to get drawing information recorded into a picture that is
  848. loaded from
  849. >a resource file. Should I call OpenPicture in addition to DrawPicture?
  850. >    resFileNum = OpenResFile( (ConstStr255Param) pictInfo[j].name);
  851. >    DrawPicture(thePicture, &r);
  852. >
  853. >    followed by a bunch of Line and LineTo operations. 
  854. >
  855. >    //save resource    
  856. >    {
  857. >    Handle pictHandle;
  858. >    PtrToHand(*thePicture, &pictHandle, (*thePicture)->picSize);
  859. >    AddResource(pictHandle, 'PICT', 401, "\p");     
  860. >    CloseResFile(resFileNum);
  861. >    }
  862. >When I tried the save thePicture, the original picture is saved to disk,
  863. not the altered
  864. >version that I want. The drawing information is never recorded into the
  865. picture
  866.  
  867. If you are trying to make a new PICT, you have to use:
  868. * OpenPicture
  869. * (QD drawing commands)
  870. * ClosePicture
  871. * AddResource
  872.  
  873. If you are trying to modify or add to an existing PICT, you need:
  874. * OpenPicture (new pic)
  875. * DrawPicture (existing pic)
  876. * (QD drawing commands)
  877. * ClosePicture (new pic)
  878. * RemoveResourse (existing pic)
  879. * AddResource
  880. You also could use ChangedResourse instead of Add/Remove, but you would
  881. have to make the existing pic the same as the new pic with something like:
  882. * SetHandleSize(0) (existing pic)
  883. * HandAndHand(new pic, existing pic)
  884. * ChangedResourse (existing pic)
  885.  
  886. +++++++++++++++++++++++++++
  887.  
  888. >From scottsquir@aol.com (ScottSquir)
  889. Date: 5 Apr 1994 02:50:04 -0400
  890. Organization: America Online, Inc. (1-800-827-6364)
  891.  
  892. In article <2npicoINNq72@srvr1.engin.umich.edu>, weip@engin.umich.edu (Patrick
  893. Wei) writes:
  894.  
  895. >Should I call OpenPicture in addition to DrawPicture?
  896.  
  897. yes, you need to do an OpenPicture to start recording QuickDraw operations
  898. and then close it to create a PICT resource.  -scott
  899.  
  900.  
  901.  
  902. +++++++++++++++++++++++++++
  903.  
  904. >From jwbaxter@olympus.net (John W. Baxter)
  905. Date: Mon, 04 Apr 1994 22:05:26 -0700
  906. Organization: Internet for the Olympic Peninsula
  907.  
  908. In article <A9C5D82708017D1A@cro.nrel.gov>, Carl R. Osterwald
  909. <carl_osterwald@nrel.gov> wrote:
  910.  
  911. > If you are trying to modify or add to an existing PICT, you need:
  912. > * OpenPicture (new pic)
  913. > * DrawPicture (existing pic)
  914. > * (QD drawing commands)
  915. > * ClosePicture (new pic)
  916. > * RemoveResourse (existing pic)
  917. > * AddResource
  918.  
  919.  
  920. Remembering along the way that the existing PICT resource is quite likely
  921. to be marked purgeable, so it may have gone away between being gotten
  922. (getPicture () or getResource () and the time above when you are ready to
  923. call DrawPicture () on it.  A LoadResource () to ensure that it's still
  924. around would be a nice idea.
  925. Or a variety of possibilities to keep it from being purged.
  926.  
  927. -- 
  928. John Baxter    Port Ludlow, WA, USA  [West shore, Puget Sound]
  929.    jwbaxter@pt.olympus.net
  930.  
  931. ---------------------------
  932.  
  933.  
  934. >From ua025@freenet.Victoria.BC.CA (Cody Jones)
  935. Subject: Speeding up animation; questions
  936. Date: Sun, 27 Mar 1994 09:13:55 GMT
  937. Organization: The Victoria Freenet Association (VIFA), Victoria, B.C., Canada
  938.  
  939.  
  940. A fair number of coders are complaining about the Mac's lack of
  941. screen-pages.  Perhaps I may suggest a technique I'm presently using.
  942. Maybe you are all already acceptably aquainted [and aggravated by my
  943. alliteration - sorry, couldn't help myself] with it, but I may as well
  944. mention it.
  945.  
  946. Divide your 8-bit palette into 2 halves.  You now have 2, 4-bit screens. 
  947. It's simple to switch screens - it's just a palette change.  You can draw
  948. directly onto the screen (using nondisplaying colors, of course) -
  949. there's no need to assemble all your images in an off-screen buffer and
  950. blit it the screen.  There's only two drawbacks: you only get 16 colors,
  951. and you need 2 copies of every sprite/background.  (Why a second copy? 
  952. Because otherwise you'd have to shift every pixel left 4 bits before
  953. drawing it onto your second page.  Slow.)
  954.  
  955. I am presently hacking away at a Doom-style engine, and using a 4-bit
  956. grayscale palette with this method looks pretty decent.  I hope that other
  957. people will also try doing decent things with this technique.
  958.  
  959. Cody Jones, Zerius Development
  960.  
  961. -- 
  962.  
  963. +++++++++++++++++++++++++++
  964.  
  965. >From pburgess@netcom.com (Phillip Burgess)
  966. Date: Sun, 27 Mar 1994 22:59:16 GMT
  967. Organization: NETCOM On-line Communication Services (408 241-9760 guest)
  968.  
  969. ua025@freenet.Victoria.BC.CA (Cody Jones) writes:
  970.  
  971. >Divide your 8-bit palette into 2 halves.  You now have 2, 4-bit screens. 
  972. >It's simple to switch screens - it's just a palette change.
  973.  
  974. The thought had occurred to me... I just assumed it would be much too slow
  975. doing all that bit wrangling to draw stuff.  How un-scientific of me!  What
  976. sort of speed improvement are you getting with this technique vs. 8-bit
  977. drawing & CopyBits?
  978.  
  979. 8-D.. .   .  <- Me, drooling like an imbecile
  980.  
  981. -- 
  982.   Phillip Burgess   (pburgess@netcom.com)
  983.  
  984. +++++++++++++++++++++++++++
  985.  
  986. >From ua025@freenet.Victoria.BC.CA (Cody Jones)
  987. Date: Mon, 28 Mar 1994 06:29:19 GMT
  988. Organization: The Victoria Freenet Association (VIFA), Victoria, B.C., Canada
  989.  
  990.  
  991. > The thought had occurred to me... I just assumed it would be much too slow
  992. > doing all that bit wrangling to draw stuff.  How un-scientific of me!  What
  993. > sort of speed improvement are you getting with this technique vs. 8-bit
  994. > drawing & CopyBits?
  995.  
  996. Unfortunately I haven't updated my sprite routines, so I can't give you
  997. any figures (yet).  But here's some points in this method's favour:
  998.  
  999. Here's how I used to do masking for sprites (ie. only one screen page). 
  1000. Note this is exactly how Maelstrom's sprite code operates.  Assume we're
  1001. working with 1 pixel here, and the mask is either a 0xFF for 'solid'
  1002. pixels and 0x00 for 'transparent' pixels:
  1003.  
  1004. 1. AND the mask with the sprite
  1005. 2. NOT the mask
  1006. 3. AND the result of step 2 with the background
  1007. 4. OR the result of step 1 with the result of step 3
  1008.  
  1009. Note that steps 1 and 2 can be done just after the sprite(s) are loaded
  1010. in; there's no need to do them every time you draw a sprite.
  1011.  
  1012. OK: here's how I draw individual pixels with the 2-buffer method.  Assume
  1013. that screen one uses the low-order nybble; screen 2 uses the high-order.
  1014. For screen 1, AND 0xF0 with a pixel taken from the screen (or your pixmap,
  1015. it doesn't matter).  This clears the nybble you'll need for step 2, which
  1016. is simply an OR with your color value.
  1017. Screen 2 is very similar: AND 0x0F with your original pixel and then OR
  1018. with your color value.  Note, however, that this color value must be
  1019. shifted left 4 bits...
  1020.  
  1021. Finally, how all this ties together!  I expect you'll like the sound of
  1022. this: NO modification to the sprite code is required.  All you need are 2
  1023. copies in memory of every sprite/background (1 per screen), and some
  1024. modification to the sprite preprocessor (steps 1 and 2 as described above
  1025. regarding normal sprite drawing).
  1026.  
  1027. Imagine a mask and sprite from a normal (?) '1-screen' display:
  1028. Mask   = 0xFF00FF
  1029. Sprite = 0x010203
  1030.  
  1031. Your sprite preprocessor would, for the screen 1 (scr1) version, involve
  1032. an additional step after the first 2: every high-order nybble from every
  1033. pixel of the mask should be set to 0xF.  Thus, when masking onto scr1, the
  1034. "mask AND background" operation preserves the contents of all scr2 pixels.
  1035. The preprocessor for scr2 is almost identical: the additional step is
  1036. instead to set every low-order nybble from every mask pixel to 0xF.
  1037.  
  1038. Whew!  A fair bit of text there!  There's some big benefits involved here,
  1039. though.  I'm assuming you're drawing directly into screen memory: using
  1040. CopyBits won't work with this technique, because you have to copy a full
  1041. screen's worth every frame *anyway*, so there's no difference...
  1042. Anyway, one major stage of memory-moving is eliminated: from the completed
  1043. off-screen buffer onto the screen.  You can draw backgrounds, sprites,
  1044. text (etc) onto the undisplaying screen, and flip the palette when the
  1045. next vertical retrace occurs.
  1046. Say you're wanting a scrolling background that's 512x384 pixels big on the
  1047. screen.  That's 196,608 bytes you no longer have to copy... which will
  1048. result in a good speed increase.
  1049.  
  1050. A wise use of colors will help mask your lack of them (16-color
  1051. grayscale looks good).
  1052.  
  1053. Have fun with this one!
  1054.  
  1055. Cody Jones, Zerius Development
  1056.  
  1057. -- 
  1058.  
  1059. +++++++++++++++++++++++++++
  1060.  
  1061. >From dwareing@apanix.apana.org.au (David Wareing)
  1062. Date: 16 Mar 94 11:51:28 GMT
  1063. Organization: Apanix Public Access Unix, +61 8 373 5485 (5 lines)
  1064.  
  1065. snozer@cats.ucsc.edu (Daniel Craig Jalkut) writes:
  1066.  
  1067.  
  1068. >In <dwareing.763359504@apanix.apana.org.au> dwareing@apanix.apana.org.au (David Wareing) writes:
  1069.  
  1070. >But the bottom line is that the Amiga can do everything the Mac can
  1071. >do, but the converse is not true.  The advantages you point out for 
  1072. >the Mac are all software(which is why i'm a mac user and no longer an 
  1073. >Amigan), if the software were written as well for the Amiga(including 
  1074. >the OS), then you'd have the equivalent of a Macintosh with the bonus
  1075. >of excellent graphics hardware.  And the Amiga computers were sold 
  1076. >for much less than macs in the past, so it's not infeasable cost-wise
  1077. >that the Macs have this type of hardware for graphics. 
  1078.  
  1079. I don't want this to become yet another brandX vs mac flamewar, but there
  1080. are many reasons why amigas have been sold for much less than macs in the
  1081. past. Amiga equipment, in general (and I'm not talking about their custom
  1082. chipsets), is piss-poor. Everything from the floppy drive (screech screech
  1083. kerklunk) to the keyboards were of a quality that made the machines look
  1084. even more like toys. You had a gui that sucked rocks. Period. You had a
  1085. system where the only way to play the majority of games, was to turn the
  1086. thing off or vulcan-nerve-pinch it, shove the disk in, and turn it on
  1087. again. You had non-existant developer support from Commodore. Commodore
  1088. themselves actively promoted their machines as "entertainment" platforms
  1089. (i.e. games machines). Until not all that long ago, a look inside an amiga
  1090. 'starter kit' would show you a handful of floppies, most of which were
  1091. games, and a few lame word-processors such as KindWords.
  1092.  
  1093. In contrast, apple equipment has been expensive, but of generally high
  1094. quality. You can't compare the Sony Trinitrons to the Philips monitors
  1095. such as Commodore's 1084 etc. You also can't compare the price.  In
  1096. comparison to the amiga, the mac is an extremely well thought out design,
  1097. and extremely well supported by both manufacturer and third parties. In
  1098. the amiga's case, the only support is from its huge third party hardware
  1099. manufacturer base and developers (most of whom appear to be of the hacker
  1100. variety).
  1101.  
  1102. That's part of the reason why the prices are much different. Which would
  1103. you prefer? A custom blitting chipset, or monitors you could actually read
  1104. word-processing text from, and an overall architecture that is consistent
  1105. and of high quality?
  1106.  
  1107. --
  1108. David Wareing
  1109. Adelaide, South Australia
  1110. dwareing@apanix.apana.org.au
  1111.  
  1112.  
  1113. +++++++++++++++++++++++++++
  1114.  
  1115. >From jmunkki@beta.hut.fi (Juri Munkki)
  1116. Date: 28 Mar 1994 19:35:12 GMT
  1117. Organization: Helsinki University of Technology
  1118.  
  1119. In article <CnBGB7.KvC@suncad.camosun.bc.ca> ua025@freenet.Victoria.BC.CA (Cody Jones) writes:
  1120. >Divide your 8-bit palette into 2 halves.  You now have 2, 4-bit screens. 
  1121. >It's simple to switch screens - it's just a palette change.  You can draw
  1122. >directly onto the screen (using nondisplaying colors, of course) -
  1123. >there's no need to assemble all your images in an off-screen buffer and
  1124. >blit it the screen.  There's only two drawbacks: you only get 16 colors,
  1125. >and you need 2 copies of every sprite/background.  (Why a second copy? 
  1126. >Because otherwise you'd have to shift every pixel left 4 bits before
  1127. >drawing it onto your second page.  Slow.)
  1128.  
  1129. Arashi (STORM) splits an 8 bit pixel into four parts: two 3 bit (7 colors+
  1130. transparency) buffers (double-buffered) and two 1 bit buffers for background
  1131. graphics. Including the background color, this gives you 10 colors to work
  1132. with.
  1133.  
  1134. Since everything is done with vector graphics, this doesn't create as much
  1135. of a performance problem as with sprites (where you would have to do at
  1136. least twice the work). The Arashi animation toolkit is available with
  1137. anonymous ftp from ics.uci.edu (pub/mac/think-c/apps or something like that).
  1138.  
  1139. There's a big catch, however...and I didn't discover it than until when the
  1140. game was pretty well along: video cards behave differently on palette changes.
  1141. Some cards wait for the next vertical blanking to switch palettes and some
  1142. cards do it immediately. Method #1 wastes time and method #2 produces
  1143. partial frames where the bottom and top do not match. With some cards,
  1144. calling the palette change from within the vertical blanking routine will
  1145. wait until the next vertical blank (stupid, stupid) and on some cards it
  1146. will simply not work at all... The video card driver specifications give
  1147. some guidelines, but it seems people are not following all those guidelines.
  1148.  
  1149. So...in my current animation kit I'm doing something totally different.
  1150. I'm not using Quickdraw, it's fast, supports 2, 4, 16, 256, 32768 and
  1151. millions of colors (with a maximum of 32768 colors), multiple screens
  1152. (the animation can be split on several screen of different depth and
  1153. different color maps) and it's completely flicker-free. (Partial frames
  1154. do occur, but it doesn't seem too bothersome and it would be pretty hard
  1155. to avoid on a system with 8 monitors, for instance.)
  1156.  
  1157. Animation timing is done with the time manager, so you can set your
  1158. frame rate to anything you want. I should have some kind of demo game
  1159. out for WWDC (May) and I will convert this software to PowerPC once
  1160. CodeWarrior ships with an inline assembler (it runs quite well under
  1161. emulation though).
  1162.  
  1163. Oh, and the class library I built on the basic animation engine supports
  1164. unrestricted scaling and rotation and warping with 2x3 matrices and it
  1165. now also supports very fast collision detection in a user coordinate system
  1166. (doesn't depend on screen resolution).
  1167.  
  1168. Finally, the animation engine is not available to developers, unless you
  1169. can be very, very convincing ($$$).
  1170.  
  1171. The first game will be something simple and will probably not show all the
  1172. neat things that can be done with the animation kit. I just want something
  1173. out there to show the world that I'm still alive and working on software...
  1174.  
  1175. -- 
  1176.   Juri Munkki            There ain't so such thing as a shareware lunch.
  1177.  jmunkki@hut.fi                Windsurfing: Faster than the wind.
  1178.  
  1179. +++++++++++++++++++++++++++
  1180.  
  1181. >From ua025@freenet.Victoria.BC.CA (Cody Jones)
  1182. Date: Tue, 29 Mar 1994 04:10:19 GMT
  1183. Organization: The Victoria Freenet Association (VIFA), Victoria, B.C., Canada
  1184.  
  1185.  
  1186. > There's a big catch, however...and I didn't discover it than until when the
  1187. > game was pretty well along: video cards behave differently on palette
  1188. > changes.  Some cards wait for the next vertical blanking to switch palettes
  1189. > and some cards do it immediately. Method #1 wastes time and method #2
  1190. > produces partial frames where the bottom and top do not match. With some
  1191. > cards, calling the palette change from within the vertical blanking routine
  1192. > will wait until the next vertical blank (stupid, stupid) and on some
  1193. > cards it will simply not work at all... The video card driver
  1194. > specifications give some guidelines, but it seems people are not following
  1195. > all those guidelines.
  1196.  
  1197. What!!  I thought that SetEntries (that's the lowest-level I could get for
  1198. palette stuff :) always waited for a vertical retrace before doing its
  1199. palette-change.  I believe I read this in an Apple document.  Are you
  1200. saying that it's really up to the card, not SetEntries?  That would mean
  1201. Apple wants this to be a standard and so goes around saying to high-level
  1202. programmers that SetEntries does the work (when that's just a fabrication).
  1203.  
  1204. If this is true... well, I'm not about to give up on a decent technique. 
  1205. The people with the wrong type of video card can play someone else's game
  1206. instead...
  1207.  
  1208. Cody Jones, Zerius Development
  1209. -- 
  1210.  
  1211. +++++++++++++++++++++++++++
  1212.  
  1213. >From dwareing@apanix.apana.org.au (David Wareing)
  1214. Date: 22 Mar 94 13:46:07 GMT
  1215. Organization: Apanix Public Access Unix, +61 8 373 5485 (5 lines)
  1216.  
  1217. rhn@netcom.com (Ron Nicholson) writes:
  1218.  
  1219. >One idea used the in Apple II days for fast graphics animation, that I
  1220. >haven't seen mentioned, is pre-shifted sprites.  Since copybits runs
  1221. >fastest when the source and distination are 32 bit aligned (64 bit for
  1222. >PowerPC), having 4 or 8 pre-aligned sprite pixmaps, would mean copybits
  1223. >would never waste any time shifting.  Has anyone experimented with
  1224. >this?
  1225.  
  1226. An easier way to do this is to create your aligned pixmaps with a call to
  1227. NewGWorld. Give it a depth of 0. This supposedly creates a pixmap that is
  1228. aligned to the screen. And yes, it is certainly worth your while. You can
  1229. get *very* nice speed increases with aligned pixmaps.
  1230.  
  1231. Repeat the following mantra until a state similar to coma is reached:
  1232.  
  1233. "GWorlds are my friends. GWorlds are my friends. GWorlds are my friends."
  1234.  
  1235. --
  1236. David Wareing
  1237. Adelaide, South Australia
  1238. Mac Games & Multimedia Programming        dwareing@apanix.apana.org.au
  1239. - --------------------------------------------------------------------
  1240.  
  1241. +++++++++++++++++++++++++++
  1242.  
  1243. >From jmunkki@beta.hut.fi (Juri Munkki)
  1244. Date: 29 Mar 1994 15:59:35 GMT
  1245. Organization: Helsinki University of Technology
  1246.  
  1247. In article <CnErL8.Ax6@suncad.camosun.bc.ca> ua025@freenet.Victoria.BC.CA (Cody Jones) writes:
  1248. >What!!  I thought that SetEntries (that's the lowest-level I could get for
  1249. >palette stuff :) always waited for a vertical retrace before doing its
  1250. >palette-change.  I believe I read this in an Apple document.  Are you
  1251. >saying that it's really up to the card, not SetEntries?  That would mean
  1252. >Apple wants this to be a standard and so goes around saying to high-level
  1253. >programmers that SetEntries does the work (when that's just a fabrication).
  1254.  
  1255. Apple's video drivers wait for the next refresh, but I have seen at least
  1256. one third party card that didn't wait for them. That was quite a few years
  1257. ago, so they might not be sold anymore.
  1258.  
  1259. Unless you use very careful timing, you'll waste up to one full frame
  1260. of CPU time by doing SetEntries-type buffer switching on most cards.
  1261.  
  1262. It's also limited to one video card because of this problem.
  1263. -- 
  1264.   Juri Munkki            There ain't so such thing as a shareware lunch.
  1265.  jmunkki@hut.fi                Windsurfing: Faster than the wind.
  1266.  
  1267. +++++++++++++++++++++++++++
  1268.  
  1269. >From sigurasg@rhi.hi.is (Sigurdur Asgeirsson)
  1270. Date: 29 Mar 1994 21:11:24 GMT
  1271. Organization: University of Iceland
  1272.  
  1273. In <2n9j97$6e@nntp.hut.fi> jmunkki@beta.hut.fi (Juri Munkki) writes:
  1274.  
  1275. >In article <CnErL8.Ax6@suncad.camosun.bc.ca> ua025@freenet.Victoria.BC.CA (Cody Jones) writes:
  1276. >>What!!  I thought that SetEntries (that's the lowest-level I could get for
  1277. >>palette stuff :) always waited for a vertical retrace before doing its
  1278. >>palette-change.  I believe I read this in an Apple document.  Are you
  1279. >>saying that it's really up to the card, not SetEntries?  That would mean
  1280. >>Apple wants this to be a standard and so goes around saying to high-level
  1281. >>programmers that SetEntries does the work (when that's just a fabrication).
  1282.  
  1283.   I believe that SetEntries is just a wrapper for a control call to the
  1284. driver, it is (naturally) the driver's work to actually set the hardware
  1285. CLUT, and to wait for the blanking interval (if it is requested to do so,
  1286. see below) since for both tasks you need to talk to the hardware.
  1287.  
  1288. >Apple's video drivers wait for the next refresh, but I have seen at least
  1289. >one third party card that didn't wait for them. That was quite a few years
  1290. >ago, so they might not be sold anymore.
  1291.  
  1292. [snip]
  1293.  
  1294.   According to C&D, the drivers are supposed to do this only if they're
  1295. called at interrupt level 0, if the interrupt level has been raised
  1296. (this is from memory, there might be a specific level required -
  1297. possibly 2) the driver should not wait for blanking (talk about weird
  1298. calling conventions, passing parameters in SR! :-).
  1299. -- 
  1300. Sigurdur Asgeirsson    | "Well you know, C isn't that hard, void (*(*f[])())()
  1301. Kambasel 26            | for instance declares f as an array of unspecified 
  1302. 109 Reykjavik, Iceland | size, of pointers to functions that return pointers to
  1303. sigurasg@rhi.hi.is     | functions that return void... I think"
  1304.  
  1305. +++++++++++++++++++++++++++
  1306.  
  1307. >From ua025@freenet.Victoria.BC.CA (Cody Jones)
  1308. Date: Wed, 30 Mar 1994 00:52:51 GMT
  1309. Organization: The Victoria Freenet Association (VIFA), Victoria, B.C., Canada
  1310.  
  1311.  
  1312. > Unless you use very careful timing, you'll waste up to one full frame
  1313. > of CPU time by doing SetEntries-type buffer switching on most cards.
  1314.  
  1315. Why?  Here's how I see it:  after doing all your drawing to the
  1316. non-displayed screen, you call SetEntries to swap the screens.  Yes, the
  1317. CPU does wait for a VR and thus waste some time between frames, but what
  1318. else can your program do with that time?  If your drawing code takes less
  1319. than 1 refresh cycle, your graphics will keep up with the retrace.  If it
  1320. takes just over 1 cycle, then your FPS rate will drop by 2x - but that's
  1321. unavoidable.
  1322.  
  1323. Cody Jones, Zerius Development
  1324.  
  1325. -- 
  1326.  
  1327. +++++++++++++++++++++++++++
  1328.  
  1329. >From jmunkki@beta.hut.fi (Juri Munkki)
  1330. Date: 30 Mar 1994 15:36:54 GMT
  1331. Organization: Helsinki University of Technology
  1332.  
  1333. In article <2na5hs$5fp@eldborg.rhi.hi.is> sigurasg@rhi.hi.is (Sigurdur Asgeirsson) writes:
  1334. >  I believe that SetEntries is just a wrapper for a control call to the
  1335. >driver, it is (naturally) the driver's work to actually set the hardware
  1336. >CLUT, and to wait for the blanking interval (if it is requested to do so,
  1337. >see below) since for both tasks you need to talk to the hardware.
  1338.  
  1339. The driver waits for the VBL. SetEntries also seems to invalidate the ctSeed
  1340. for the gDevice, so calling GetNextEvent or WaitNextEvent can cause a lot of
  1341. extra processing to happen when Finder tries to figure out what happened.
  1342.  
  1343. Because of this, Arashi calls the driver directly.
  1344.  
  1345. >  According to C&D, the drivers are supposed to do this only if they're
  1346. >called at interrupt level 0, if the interrupt level has been raised
  1347. >(this is from memory, there might be a specific level required -
  1348. >possibly 2) the driver should not wait for blanking (talk about weird
  1349. >calling conventions, passing parameters in SR! :-).
  1350.  
  1351. Either I missed this or this is a new spec. Designing Cards & Drivers has
  1352. been updated several times and I wrote the Arashi animation code years ago.
  1353.  
  1354. I tried making the call from the vertical blanking interrupt (what's the
  1355. interrupt level for those?), from a time manager task (very unreliable)
  1356. and from the program itself.
  1357.  
  1358. -- 
  1359.   Juri Munkki            There ain't so such thing as a shareware lunch.
  1360.  jmunkki@hut.fi                Windsurfing: Faster than the wind.
  1361.  
  1362. +++++++++++++++++++++++++++
  1363.  
  1364. >From Bruce_Burkhalter@inetlink.berksys.com (Bruce Burkhalter)
  1365. Date: 30 Mar 1994 17:46:17 GMT
  1366. Organization: Berkeley Systems
  1367.  
  1368. In article <2nc6am$gui@nntp.hut.fi>, jmunkki@beta.hut.fi (Juri Munkki)
  1369. wrote:
  1370.  
  1371. > In article <2na5hs$5fp@eldborg.rhi.hi.is> sigurasg@rhi.hi.is (Sigurdur Asgeirsson) writes:
  1372. > >  I believe that SetEntries is just a wrapper for a control call to the
  1373. > >driver, it is (naturally) the driver's work to actually set the hardware
  1374. > >CLUT, and to wait for the blanking interval (if it is requested to do so,
  1375. > >see below) since for both tasks you need to talk to the hardware.
  1376. > The driver waits for the VBL. SetEntries also seems to invalidate the ctSeed
  1377. > for the gDevice, so calling GetNextEvent or WaitNextEvent can cause a lot of
  1378. > extra processing to happen when Finder tries to figure out what happened.
  1379. > Because of this, Arashi calls the driver directly.
  1380.  
  1381. A couple After Dark modules do this as well.  Making the Control() call is
  1382. a lot faster than SetEntries().  A neat trick you can do if you want to
  1383. cycle the table continously is to make a copy of the table immediately
  1384. following the it.  To cycle through the colors, you just increment your ptr
  1385. and reset it to the top when you get to 255.
  1386.  
  1387. -- 
  1388. Bruce Burkhalter
  1389. Bruce_Burkhalter@inetlink.berksys.com
  1390. All opinions are mine.
  1391. Berkeley Systems Inc.
  1392.  
  1393. +++++++++++++++++++++++++++
  1394.  
  1395. >From jmunkki@beta.hut.fi (Juri Munkki)
  1396. Date: 30 Mar 1994 22:11:36 GMT
  1397. Organization: Helsinki University of Technology
  1398.  
  1399. In article <CnGD44.361@suncad.camosun.bc.ca> ua025@freenet.Victoria.BC.CA (Cody Jones) writes:
  1400. >> Unless you use very careful timing, you'll waste up to one full frame
  1401. >> of CPU time by doing SetEntries-type buffer switching on most cards.
  1402. >
  1403. >Why?  Here's how I see it:  after doing all your drawing to the
  1404. >non-displayed screen, you call SetEntries to swap the screens.  Yes, the
  1405. >CPU does wait for a VR and thus waste some time between frames, but what
  1406. >else can your program do with that time?  If your drawing code takes less
  1407. >than 1 refresh cycle, your graphics will keep up with the retrace.  If it
  1408. >takes just over 1 cycle, then your FPS rate will drop by 2x - but that's
  1409. >unavoidable.
  1410.  
  1411. You could start calculating stuff for the next frame.
  1412.  
  1413. The way Arashi works is that it sets a game rate goal of 20 steps per
  1414. second. On most monitors, this isn't an even multiple of the vertical
  1415. blanking rate. Depending on what is happening in the game and depending
  1416. what the game is running on, it may not be possible to display 20 frames
  1417. per second. If this happens (as it often happens on the Color Classic and
  1418. other slow machines), no drawing is done even though the game keeps running.
  1419. This temporarily drops the frame rate to 10 fps or even lower.
  1420.  
  1421. What I'm trying to say is that there's no way to tell how long it is going
  1422. to take to process one game step or wether that game step is going to draw
  1423. at all. In the future, I might want to write a game that runs at 100 fps
  1424. or more internally and draw as often as possible. In this case, any waiting
  1425. in an interrupt routine will be time wasted and will increase the probability
  1426. that frames will have to be "skipped".
  1427.  
  1428. Running at a fast enough internal rate sometimes makes hit and collision
  1429. testing easier without being too costly otherwise.
  1430.  
  1431. And, as I said in another posting, having to wait for one card makes it
  1432. very hard to use this method on two or more cards.
  1433.  
  1434. Another thing where at least two buffers are useful is displaying objects
  1435. in stereo 3D for LC shutter glasses. (You need four buffers for double-
  1436. buffering stereo 3D.) In the four buffer case you will be drawing into
  1437. two of the buffers and flipping between the other two. Any time wasted
  1438. is away from the time that you have available for drawing the next frame.
  1439. In stereo 3D applications, anything below the true vertical blanking rate
  1440. of the monitor is too slow.
  1441.  
  1442. Fortunately, I think that machines are now getting fast enough so that
  1443. these things can be more flexibly done with software solutions. This is
  1444. better for the user, because it does not limit the amount of colors (you
  1445. can do it in 15 or 24 bit color if you want) and you do not force the
  1446. user to a certain bit depth.
  1447.  
  1448. -- 
  1449.   Juri Munkki            There ain't so such thing as a shareware lunch.
  1450.  jmunkki@hut.fi                Windsurfing: Faster than the wind.
  1451.  
  1452. +++++++++++++++++++++++++++
  1453.  
  1454. >From sigurasg@rhi.hi.is (Sigurdur Asgeirsson)
  1455. Date: 31 Mar 1994 13:22:12 GMT
  1456. Organization: University of Iceland
  1457.  
  1458. In <2nc6am$gui@nntp.hut.fi> jmunkki@beta.hut.fi (Juri Munkki) writes:
  1459.  
  1460. >In article <2na5hs$5fp@eldborg.rhi.hi.is> sigurasg@rhi.hi.is (Sigurdur Asgeirsson) writes:
  1461. [snip]
  1462. >>  According to C&D, the drivers are supposed to do this only if they're
  1463. >>called at interrupt level 0, if the interrupt level has been raised
  1464. >>(this is from memory, there might be a specific level required -
  1465. >>possibly 2) the driver should not wait for blanking (talk about weird
  1466. >>calling conventions, passing parameters in SR! :-).
  1467.  
  1468. >Either I missed this or this is a new spec. Designing Cards & Drivers has
  1469. >been updated several times and I wrote the Arashi animation code years ago.
  1470.  
  1471.   In my copy of C&D second edition, on page 185 (in the description of
  1472. the SetEntries routine in the DRVR code example) there is the following
  1473. text:
  1474.  
  1475.   2) If SetEntries is entered while the interrupt level is non-zero,
  1476.      it should write immediately to the CLUT hardware.
  1477.  
  1478.   However, this is in reference to an optional feature of the driver,
  1479. that of doing CLUT updates asyncronously, so drivers aren't required to
  1480. do this.
  1481.  
  1482. -- 
  1483. Sigurdur Asgeirsson    | "Well you know, C isn't that hard, void (*(*f[])())()
  1484. Kambasel 26            | for instance declares f as an array of unspecified 
  1485. 109 Reykjavik, Iceland | size, of pointers to functions that return pointers to
  1486. sigurasg@rhi.hi.is     | functions that return void... I think"
  1487.  
  1488. +++++++++++++++++++++++++++
  1489.  
  1490. >From jmunkki@beta.hut.fi (Juri Munkki)
  1491. Date: 31 Mar 1994 20:40:29 GMT
  1492. Organization: Helsinki University of Technology
  1493.  
  1494. In article <2neiq4$rth@eldborg.rhi.hi.is> sigurasg@rhi.hi.is (Sigurdur Asgeirsson) writes:
  1495. >  In my copy of C&D second edition, on page 185 (in the description of
  1496. >the SetEntries routine in the DRVR code example) there is the following
  1497. >text:
  1498. >
  1499. >  2) If SetEntries is entered while the interrupt level is non-zero,
  1500. >     it should write immediately to the CLUT hardware.
  1501. >
  1502. >  However, this is in reference to an optional feature of the driver,
  1503. >that of doing CLUT updates asyncronously, so drivers aren't required to
  1504. >do this.
  1505.  
  1506. Now I remember it. I tried and it and found it very unreliable. Apple's
  1507. drivers tended to wait for the next VB period no matter how I called them.
  1508. (I think I was using a TOBY 8 bit card on a Mac II... at least that card
  1509. supported multiple pages. My Quadra 700 doesn't have support for more than
  1510. one video page.)
  1511.  
  1512. -- 
  1513.   Juri Munkki            There ain't so such thing as a shareware lunch.
  1514.  jmunkki@hut.fi                Windsurfing: Faster than the wind.
  1515.  
  1516. ---------------------------
  1517.  
  1518. >From jhiggins@mathworks.com (John M. Higgins)
  1519. Subject: Tools to improve segmentation?
  1520. Date: 24 Mar 1994 21:13:33 GMT
  1521. Organization: The MathWorks, Inc.
  1522.  
  1523. Are there any tools which help optimize CODE segmentation by monitoring
  1524. frequency of intersegment calls and segment use?
  1525.  
  1526. -- 
  1527. John M. Higgins
  1528. The MathWorks, Inc.
  1529. jhiggins@mathworks.com
  1530.  
  1531. +++++++++++++++++++++++++++
  1532.  
  1533. >From ari@world.std.com (Ari I Halberstadt)
  1534. Date: Mon, 4 Apr 1994 04:20:07 GMT
  1535. Organization: The World Public Access UNIX, Brookline, MA
  1536.  
  1537. In article <jhiggins-240394161555@144.212.1.91>,
  1538. John M. Higgins <jhiggins@mathworks.com> wrote:
  1539. >Are there any tools which help optimize CODE segmentation by monitoring
  1540. >frequency of intersegment calls and segment use?
  1541.  
  1542. Efficient segmentation of applications has troubled me since my first
  1543. multisegment Macintosh application. Unfortunately, due to the lack of
  1544. tools to automatically segment applications, the only practical
  1545. solution I've found has been to effectively ignore the problem.
  1546. Fortunately, this is finally a reasonably viable approach, as the
  1547. PowerPC no longer uses segmented applications.
  1548.  
  1549. That said, this is what I've managed to do with my messing around in
  1550. the Segment Loader.
  1551.  
  1552. You can arrange to have inactive segments unloaded automatically. An
  1553. inactive segment is a segment that does not contain the program
  1554. counter and which is not pointed to by a return address on the stack.
  1555. To unload inactive segments, you need to walk the stack to access all
  1556. of the return addresses that are pointed to by register a6. You can
  1557. then search for the segments containing the return addresses from
  1558. among all segments that are in memory. All segments found to contain a
  1559. return address are deemed active and are not unloaded. All other
  1560. segments can be unloaded with UnloadSeg. There are some complications
  1561. to this scheme that can arise if you attempt to unload segments from a
  1562. routine called by the OS or if you are using a multi-threaded
  1563. application. You also must know the format of the jump table produced
  1564. by your compiler. This is somewhat similar to what Windows does to
  1565. manage program segments, though Windows goes a step further and can
  1566. unload active segments as well as inactive segments. I have
  1567. implemented the above algorithm in Winter Shell, though support for
  1568. multiple threads is not present yet in the current released version.
  1569.  
  1570. You can use a program to generate a function call tree for your
  1571. application. For instance, you can use the "cflow" program on a Unix
  1572. system to generate a function call tree. Cflow supports two forms of
  1573. function call trees. The default format shows the function call
  1574. sequence, while a reversed format lists all functions that call a
  1575. function. I have found the reversed format to be most useful.
  1576. Unfortunately, the version of cflow that I have used omits many
  1577. functions from its listings. To process Macintosh source code also
  1578. requires uploading the code to a Unix machine (assuming you don't have
  1579. A/UX). Since cflow doesn't have access to all of the Macintosh header
  1580. files, it tends to produce volumes of error messages (5 megs for 1 meg
  1581. of source code) that should be redirected to /dev/null. Once you have
  1582. a function call tree, you can get some idea of how functions might
  1583. most efficiently be segmented.
  1584.  
  1585. To gather segment usage statistics, you can use the compiler's
  1586. profiler. In THINK C, you can modify the profiler to gather
  1587. information about the segment containing the profiled functions. Even
  1588. if you can't modify your compiler's profiler, you could generate a
  1589. link map for your application and use a script to correlate the link
  1590. map with the profiler's output. You could also patch the _LoadSeg trap
  1591. and gather statistics when it is executed, but you will need to unload
  1592. the application's segments for it to be called with any regularity.
  1593.  
  1594. I have tried segmenting a large program (again, Winter Shell) into
  1595. many small segments with only one file per segment. This turned out to
  1596. be a poor method to segment applications. In the current development
  1597. version of Winter Shell I have simply segmented the application in a
  1598. manner that is most convenient and logical for me, the programmer.
  1599. With the new segmentation scheme, Winter Shell doesn't require much
  1600. more memory than it did with the former method. Furthermore, the
  1601. application spends less time loading and unloading segments.
  1602.  
  1603. Today, most applications can assume that all of their code can be
  1604. loaded into memory (or virtual memory). This assumption greatly
  1605. simplifies segmentation, since you effectively don't have to worry
  1606. about it. In the extreme case, you could just use far-code and one
  1607. huge segment and forget about the whole issue. I used this extremely
  1608. lazy approach to port a large 600K Unix application to the Macintosh.
  1609. If you expect your application will run in a memory partition that
  1610. will not allow all of its code to be resident, then you will obviously
  1611. need to work out a good segmentation strategy. If your application's
  1612. memory usage peaks while performing certain operations, then you could
  1613. optimize the segmentation towards those peak operations. For instance,
  1614. when printing, you could unload most of your application's code.
  1615.  
  1616. The automatic segment unloading code that I mentioned above is in the
  1617. file "SegmentLib.c" in Winter Shell. Winter Shell is a free
  1618. application framework written in C. You can retrieve Winter Shell
  1619. 1.0d2 by ftp'ing any of the following files:
  1620.  
  1621.   sumex-aim.stanford.edu:/info-mac/dev/src/winter-shell-10d2-c.hqx
  1622.   mac.archive.umich.edu:/mac/development/source/wintershell1.0d2.sit.hqx
  1623.  
  1624. umich also has three mirrors that are updated daily:
  1625.  
  1626.        "wuarchive.wustl.edu" in the directory "mirrors/archive.umich.edu",
  1627.                                         (apple2,mac,atari,msdos,next)
  1628.        "src.doc.ic.ac.uk"    in the directory  "packages/mac/umich",
  1629.   and  "archie.au"           in the directory  "micros/mac/umich".
  1630.  
  1631. there are additional mirrors of info-mac in Europe, among them
  1632.  
  1633.   nic.switch.ch (Switzerland)
  1634.   metten.fenk.wau.nl (The Netherlands)
  1635.   swdsrv.edvz.univie.ac.at (Austria)
  1636.  
  1637. Several people have mentioned the lack of documentation for Winter
  1638. Shell. I'm working on an update to Winter Shell that will include at
  1639. least some automatically extracted documentation that will provide
  1640. minimal comments for all of the functions in Winter Shell. The update
  1641. will also add a better event handling mechanism. I will probably also
  1642. add a "ws_" prefix to all externally defined functions and symbols to
  1643. prevent symbol name conflicts. No promises on when it will be
  1644. available though.
  1645. -- 
  1646. Ari Halberstadt    ari@world.std.com     #include <std/disclaimer.h>
  1647. "These beetles were long considered to be very rare because very few
  1648. entomologists look for beetles in the mountains, in winter, at night,
  1649. during snow storms." -- Purves W. K., et al, "Life: The Science of
  1650.  
  1651. ---------------------------
  1652.  
  1653. >From dsf5454@ritvax.isc.rit.edu
  1654. Subject: copy file question, code available?
  1655. Date: Wed, 30 Mar 1994 18:42:23 GMT
  1656. Organization: Rochester Institute of Technology
  1657.  
  1658. Hello...
  1659.     I'm curious if there are any routines available to copy a file to a
  1660. different subdirectory..? I'm certainly interested in finding out as I have a
  1661. need for such a beast... even the pseudocode or tips on how to do one would
  1662. help.. thanks! Much appreciated.
  1663.  
  1664. -Dan Foster
  1665. Internet:    dsf5454@ritvax.isc.rit.edu
  1666. BITNET/CREN:    dsf5454@ritvax.BITNET
  1667.  
  1668.  
  1669. +++++++++++++++++++++++++++
  1670.  
  1671. >From jumplong@aol.com (Jump Long)
  1672. Date: 30 Mar 1994 21:48:02 -0500
  1673. Organization: America Online, Inc. (1-800-827-6364)
  1674.  
  1675. In article <1994Mar30.184223.9555@ultb.isc.rit.edu>, dsf5454@ritvax.isc.rit.edu
  1676. writes:
  1677.  
  1678. > I'm curious if there are any routines available to copy a file to a
  1679. > different subdirectory..? I'm certainly interested in finding out as I have a
  1680. > need for such a beast... even the pseudocode or tips on how to do one would
  1681. > help.. thanks! Much appreciated.
  1682.  
  1683. Dan, look at the MoreFiles sample code from Apple DTS. It available on the last
  1684. few Developer CDs and at Apple's FTP site.
  1685.  
  1686. - Jim Luther
  1687.  
  1688.  
  1689. +++++++++++++++++++++++++++
  1690.  
  1691. >From kenlong@netcom.com (Ken Long)
  1692. Date: Thu, 31 Mar 1994 18:06:12 GMT
  1693. Organization: NETCOM On-line Communication Services (408 241-9760 guest)
  1694.  
  1695. Also, there's a demo of that beast, complete with tooth and claw, in the 
  1696. "Other K&R's" Mac Prog Secrets source.
  1697.  
  1698. -Ken-
  1699.  
  1700. +++++++++++++++++++++++++++
  1701.  
  1702. >From rollin@newton.apple.com (Keith Rollin)
  1703. Date: Fri, 1 Apr 1994 00:37:51 GMT
  1704. Organization: Little to none
  1705.  
  1706. In article <kenlongCnJJMC.J7u@netcom.com>, kenlong@netcom.com (Ken Long)
  1707. wrote:
  1708.  
  1709. > Also, there's a demo of that beast, complete with tooth and claw, in the 
  1710. > "Other K&R's" Mac Prog Secrets source.
  1711.  
  1712. I can't remember if this was mentioned in an earlier part of the thread,
  1713. but Jim Luther of Mac DTS has released a package called MoreFiles (now in
  1714. version 1.1.1). This package has a lot of File Manager utilities (such as
  1715. pre-7.0 glue for the FSSpec routines). One of the utilities is a file copy
  1716. routine that does everything the exact right way. I haven't poured over the
  1717. code yet to see how it works, but I know this guy, and he does good work.
  1718. I'd trust his version over mine (for instance, his version works with
  1719. AppleShare drop boxes, and mine doesn't).
  1720.  
  1721. The package can be found on ftp.apple.com in /dts/mac/sc.
  1722.  
  1723. - --------------------------------------------------------------------------
  1724. Keith Rollin --- Phantom Programmer --- Apple Computer, Inc. --- Team
  1725. Newton
  1726.  
  1727. +++++++++++++++++++++++++++
  1728.  
  1729. >From jumplong@aol.com (Jump Long)
  1730. Date: 3 Apr 1994 14:02:02 -0400
  1731. Organization: America Online, Inc. (1-800-827-6364)
  1732.  
  1733. In article <rollin-310394163751@rollin-keith.apple.com>,
  1734. rollin@newton.apple.com (Keith Rollin) writes:
  1735.  
  1736. > I haven't poured over the  yet to see how it works, but I know this guy,
  1737. > and he does good work.
  1738.  
  1739. It works and I've only made one minor change to it lately. The next version of
  1740. FileCopy won't attempt to copy empty forks (that makes it work better with
  1741. foreign file systems that don't support multiple forks natively).
  1742.  
  1743. - Jim Luther
  1744.  
  1745.  
  1746. ---------------------------
  1747.  
  1748. >From guapo@news.cs.columbia.edu (J. Robert Diana)
  1749. Subject: skeleton code generators?
  1750. Date: 28 Mar 1994 08:42:40 -0500
  1751. Organization: Columbia University Department of Computer Science
  1752.  
  1753.  
  1754. Are there any free/shareware code generators for C?  I do not need to see full
  1755. prgrams, just some things like what one would do to make Mac specific stuff.
  1756. I have found that trying to study a fully implemented program is quite a 
  1757. hassle.
  1758. Any info is greatly appreciated.
  1759. Thanks in advance.
  1760.  
  1761. Rob Diana
  1762. guapo@cs.columbia.edu
  1763.  
  1764. +++++++++++++++++++++++++++
  1765.  
  1766. >From chuck@gte.com (Chuck Hoffman)
  1767. Date: Fri, 1 Apr 1994 16:37:21 GMT
  1768. Organization: GTE Laboratories
  1769.  
  1770. In article <2n6msg$b2d@ground.cs.columbia.edu>, guapo@news.cs.columbia.edu
  1771. (J. Robert Diana) wrote:
  1772.  
  1773. > Are there any free/shareware code generators for C?  I do not need to see full
  1774. > prgrams, just some things like what one would do to make Mac specific stuff.
  1775. > I have found that trying to study a fully implemented program is quite a 
  1776. > hassle.
  1777. > Any info is greatly appreciated.
  1778. > Thanks in advance.
  1779.  
  1780. Chassis 6.0 is not a code generator.  It is a basic application framework
  1781. which you might find useful anyway.  It is not as confusing to look at as a
  1782. fully developed application, and there is a program flow-chart provided
  1783. with the code.
  1784.  
  1785. I am working on Chassis 6.1 right now, which will be AppleEvent aware.
  1786.  
  1787. Chassis 6.0 compiles with either THINK C 6 or 5.  6.1 will compile only
  1788. with THINK C 6.
  1789.  
  1790. Don't use the version of Chassis at sumex-aim.stanford.edu.  They have an
  1791. old version which is not 32-bit clean.  They never posted the new version.
  1792.  
  1793. Chassis is in the following anonymous ftp locations:
  1794.  
  1795. ftp.gte.com:
  1796. /pub/chuck/Chassis_6.0.sea.hqx
  1797.  
  1798. mac.archive.umich.edu:
  1799. /mac/development/source/chassis6.0.cpt.hqx
  1800.  
  1801. -- 
  1802. Chuck Hoffman
  1803. GTE Laboratories, Waltham, MA, USA
  1804. 617-466-2131
  1805. - ------------------------------------------------
  1806. I'm not sure why we're here, but I am sure that
  1807. while we're here we're supposed to help each other.
  1808. - ------------------------------------------------
  1809.  
  1810. +++++++++++++++++++++++++++
  1811.  
  1812. >From jumplong@aol.com (Jump Long)
  1813. Date: 3 Apr 1994 13:51:02 -0400
  1814. Organization: America Online, Inc. (1-800-827-6364)
  1815.  
  1816. In article <2n6msg$b2d@ground.cs.columbia.edu>, guapo@news.cs.columbia.edu (J.
  1817. Robert Diana) writes:
  1818.  
  1819. > Are there any free/shareware code generators for C?
  1820.  
  1821. You might want to get a copy of AppsToGo, a shell from Apple Developer
  1822. Technical Support. There are a couple of sample applications built with
  1823. AppsToGo that you can look at, too (DTS Draw and Kibitz). Available on Apple's
  1824. Developer CD and FTP site.
  1825.  
  1826. - Jim Luther
  1827.  
  1828. ---------------------------
  1829.  
  1830. End of C.S.M.P. Digest
  1831. **********************
  1832.  
  1833.  
  1834.  
  1835.